package com.ghsc.ghxc.jsb.ui.live.view

import android.content.Context
import android.content.Intent
import android.os.Bundle
import com.alibaba.dingpaas.interaction.ImSendMessageToGroupReq
import com.alibaba.dingpaas.interaction.ImSendMessageToGroupRsp
import com.aliyun.aliinteraction.InteractionEngine
import com.aliyun.aliinteraction.uikit.core.LiveConst
import com.aliyun.auipusher.LiveParam
import com.blankj.utilcode.util.GsonUtils
import com.cn.appcore.ext.loge
import com.aliyun.aliinteraction.base.Callback
import com.aliyun.aliinteraction.base.Error
import com.ghsc.ghxc.jsb.config.CustSignKey
import com.ghsc.ghxc.jsb.ui.live.activity.LiveBroadcastActivity

/**
 * 项目：JingShortVideo
 * 包名：com.bbl.jyShortVideo.ui.video.live
 * 类名：Router
 * 创建时间：2022/11/30 15:10
 * 创建人 @author： xiaolin
 * 描述 ：Todo...
 */
object CustRouter {





    //跳转直播页面  LiveBroadcastActivity
    fun openBusinessRoomPage(context: Context, liveParam: LiveParam?) {
        val intent = Intent(context, LiveBroadcastActivity::class.java)
        var bundle = Bundle()
        bundle.putSerializable(LiveConst.PARAM_KEY_LIVE_PARAM, liveParam)
        intent.putExtras(bundle)
        context.startActivity(intent)
    }



    //上架和下架推送 观众刷新
    fun sendRefreshMsg(pid :String, mGroupId:String){
        // 1. 向组内全员发消息
        val req = ImSendMessageToGroupReq()
        req.groupId =mGroupId
        // 指定消息类型
        req.type = CustSignKey.LIVE_IM_GOODS_ADD_DEL
        // 指定是否跳过安全审核
        req.skipAudit = true
        // 指定是否跳过禁言处理
        req.skipMuteCheck = true
        // 指定发送数据
        req.data = GsonUtils.getGson().toJson(object : HashMap<String?, Any?>() {
            init {
                put("pid", pid)

            }
        })
        var interactionService = InteractionEngine.instance().interactionService
        interactionService.sendMessageToGroup(req,object :
            Callback<ImSendMessageToGroupRsp> {
            override fun onSuccess(p0: ImSendMessageToGroupRsp?) {
                loge("发送成功")
            }



            override fun onError(p0: Error?) {

            }

        })
    }


    //直播间黑名单add  和del
    fun sendLiveBlackMsg(content :String, mGroupId:String,type:Int){
        // 1. 向组内全员发消息
        val req = ImSendMessageToGroupReq()
        req.groupId =mGroupId
        // 指定消息类型
        req.type = CustSignKey.LIVE_IM_BLACK_ADD_ADD
        // 指定是否跳过安全审核
        req.skipAudit = true
        // 指定是否跳过禁言处理
        req.skipMuteCheck = true
        // 指定发送数据
        req.data = GsonUtils.getGson().toJson(object : HashMap<String?, Any?>() {
            init {
                put("content", content)
                put("type", type)
            }
        })
        var interactionService = InteractionEngine.instance().interactionService
        interactionService.sendMessageToGroup(req,object :
            Callback<ImSendMessageToGroupRsp> {
            override fun onSuccess(p0: ImSendMessageToGroupRsp?) {
                loge("发送成功")
            }
            override fun onError(p0: Error?) {
            }

        })
    }

    //直播间黑 发送弹幕
    fun sendLiveBuyGoodsMsg(mGroupId:String, content :String ){
        // 1. 向组内全员发消息
        val req = ImSendMessageToGroupReq()
        req.groupId =mGroupId
        // 指定消息类型
        req.type = CustSignKey.LIVE_IM_BUY_GOODS
        // 指定是否跳过安全审核
        req.skipAudit = true
        // 指定是否跳过禁言处理
        req.skipMuteCheck = true
        // 指定发送数据
        req.data = GsonUtils.getGson().toJson(object : HashMap<String?, Any?>() {
            init {
                put("content", content)
            }
        })
        var interactionService = InteractionEngine.instance().interactionService
        interactionService.sendMessageToGroup(req,object :
            Callback<ImSendMessageToGroupRsp> {
            override fun onSuccess(p0: ImSendMessageToGroupRsp?) {
                loge("发送成功")
            }
            override fun onError(p0: Error?) {
            }

        })
    }

    //直播间发红包 通知观众
    fun sendLiveAllMsg(mGroupId:String, packetid :String,time :Int ,userId :String,userName :String,content :String){
        // 1. 向组内全员发消息
        val req = ImSendMessageToGroupReq()
        req.groupId = mGroupId
        // 指定消息类型
        req.type = CustSignKey.LIVE_IM_RED
        // 指定是否跳过安全审核
        req.skipAudit = true
        // 指定是否跳过禁言处理
        req.skipMuteCheck = true
        // 指定发送数据
        req.data = GsonUtils.getGson().toJson(object : java.util.HashMap<String?, Any?>() {
            init {
                put("packetid",packetid)
                put("time", time)
                put("userId", userId)
                put("userName", userName)
                put("content", content)
            }
        })
        var interactionService = InteractionEngine.instance().interactionService
        interactionService.sendMessageToGroup(req,object :
            Callback<ImSendMessageToGroupRsp>{
            override fun onSuccess(p0: ImSendMessageToGroupRsp?) {
                loge("发送成功")
            }
            override fun onError(p0: Error?) {
            }

        })
    }


    //直播间 通知别人。人数的变化
    fun sendLiveRenCountMsg(mGroupId:String, content :String ){
        // 1. 向组内全员发消息
        val req = ImSendMessageToGroupReq()
        req.groupId =mGroupId
        // 指定消息类型
        req.type =300010
        // 指定是否跳过安全审核
        req.skipAudit = true
        // 指定是否跳过禁言处理
        req.skipMuteCheck = true
        // 指定发送数据
        req.data = GsonUtils.getGson().toJson(object : HashMap<String?, Any?>() {
            init {
                put("content", content)
            }
        })
        var interactionService = InteractionEngine.instance().interactionService
        interactionService.sendMessageToGroup(req,object :
            Callback<ImSendMessageToGroupRsp> {
            override fun onSuccess(p0: ImSendMessageToGroupRsp?) {
                loge("发送成功")
            }
            override fun onError(p0: Error?) {
            }

        })
    }





}